package io.gitee.zhangbinhub.admin.resource.server

import io.gitee.zhangbinhub.admin.resource.server.nami.client.CommonOauthServer
import io.gitee.zhangbinhub.admin.resource.server.nami.client.WorkFlowServer
import io.gitee.zhangbinhub.admin.resource.server.nami.filter.NamiHeaderFilter
import org.noear.nami.Nami
import org.noear.nami.channel.http.HttpChannel
import org.noear.nami.coder.snack4.Snack4Decoder
import org.noear.nami.coder.snack4.Snack4Encoder
import org.noear.solon.annotation.Bean
import org.noear.solon.annotation.Configuration
import org.noear.solon.cloud.tracing.integration.NamiFilterTracing

@Configuration
class AcpAdminNamiClientAutoConfiguration {
    @Bean
    fun commonOauthServer(): CommonOauthServer = Nami.builder()
        .encoder(Snack4Encoder.instance)
        .decoder(Snack4Decoder.instance)
        .channel(HttpChannel.instance)
        .filterAdd(NamiHeaderFilter())
        .filterAdd(NamiFilterTracing())
        .create(CommonOauthServer::class.java)

    @Bean
    fun workFlowServer(): WorkFlowServer = Nami.builder()
        .encoder(Snack4Encoder.instance)
        .decoder(Snack4Decoder.instance)
        .channel(HttpChannel.instance)
        .filterAdd(NamiHeaderFilter())
        .filterAdd(NamiFilterTracing())
        .create(WorkFlowServer::class.java)
}